<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Dashboard Template for Bootstrap</title>
    <!-- Bootstrap core CSS -->
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link th:href="@{/css/dashboard.css}" rel="stylesheet">


    <style type="text/css">
        /* Chart.js */

        @-webkit-keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

        @keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

        .chartjs-render-monitor {
            -webkit-animation: chartjs-render-animation 0.001s;
            animation: chartjs-render-animation 0.001s;
        }
    </style>
</head>

<body>
<div th:replace="~{common/commons::topbar}"></div>

<div class="container-fluid">
    <div class="row">
        <div th:replace="~{common/commons::sidebar(active='cardList.html')}"></div>

        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
            <h2>发放考勤卡</h2>
            <form th:action="@{/addCard}" method="post">
                <div class="form-group">
                    <label>部门</label>
                    <!--提交的是部门的ID-->
                    <select class="form-control" name="departmentid" id="departmentid" required>
                        <option value="">请选择</option>
                        <option  th:each="dept:${departments}" th:text="${dept.departmentname}" th:value="${dept.id}">1</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>员工</label>
                    <!--提交的是部门的ID-->
                    <select class="form-control" name="employeeid" id="employeeid" required>
                        <option value="">请选择</option>
                        <option  th:each="epm:${emps}" th:text="${emp.employeename}" th:value="${emp.id}">1</option>
                    </select>
                </div>
                <button type="submit" class="btn btn-primary">提交</button>
            </form>
        </main>
    </div>
</div>

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script type="text/javascript" th:src="@{/js/jquery-3.2.1.slim.min.js}"></script>
<script type="text/javascript" th:src="@{/js/popper.min.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap.min.js}"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>

<!--		日期组件-->
<script type="text/javascript" th:src="@{/laydate/laydate.js}"></script>
<!-- 改成你的路径 -->
<script>
    $("#departmentid").change(function () {
        var departmentid = $("#departmentid").val();
        if (departmentid == null) {
            return;
        }
        $.ajax({
            cache: true,
            type: "get",
            url: "http://localhost:8080/getEmps",
            data:{"departmentid":departmentid},
            success: function (data) {
                console.log("------------------"+data);
                var employeeid = $("#employeeid").empty();
                employeeid.append('<option>请选择职工</option>');
                for (let i = 0; i < data.length; i++) {
                    employeeid.append("<option value='"+data[i].id+"'>" + data[i].employeename + "</option>");
                }
            }
        })
    })
</script>
</body>

</html>